<template>
	<view class="no-warpper">
		<!-- <search></search> -->
		<view class="nl-shadow-box">
			<view class="nl-flex-title"><text>查询条件</text></view>

			<view class="nl-flex-list" @click="selectFloor()">
				<text class="nl-margin-right">楼栋</text>
				<view :class="data.floorName ? 'right':'right-grey'">{{data.floorName ? data.floorName : '请选择楼栋'}}</view>
				<u-icon class="margin-left" name="arrow-right" color="#414141" size="24"></u-icon>
			</view>

			<view class="nl-flex-list" @click="selectUnit()">
				<text class="nl-margin-right">单元</text>
				<view :class="data.unitNum ? 'right':'right-grey'">{{data.unitNum ? data.unitNum+"单元" : '请选择单元'}}</view>
				<u-icon class="margin-left" name="arrow-right" color="#414141" size="24"></u-icon>
			</view>
			<view class="nl-flex-list" @click="selectHouse()">
				<text class="nl-margin-right">房屋</text>
				<view :class="data.roomNum ? 'right':'right-grey'">{{data.roomNum ? data.roomNum+"室": '请选择房屋'}}</view>
				<u-icon class="margin-left" name="arrow-right" color="#414141" size="24"></u-icon>
			</view>
			<view class="button-lg" @click="Launch()">
				<button>查询</button>
			</view>
		</view>
	</view>
</template>

<script>
	import goToUrl from '@/common/goToUrl.js'
	export default {
		data() {
			return {
				data: {
					floorName: '',
					floorId: '',
					unitNum: '',
					unitId: '',
					roomNum: '',
					roomId: '',
				}
			}
		},
		onShow() {
			// console.log('获取当前页面data',this.data)	
		},
		onLoad(option) {
			console.log('option',option)
			this.data.floorName = option.floorName
			this.data.floorId = option.floorId

			this.data.unitNum = option.unitNum
			this.data.unitId = option.unitId
		},
		methods: {
			Launch() {
				let param = {
					floorName: this.data.floorName,
					unitNum: this.data.unitNum,
					roomNum: this.data.roomNum,
					roomId: this.data.roomId
				}

				let text = '';
				let state = '0';

				if (!this.data.floorId && state == '0') {
					text = '请选择楼栋'
					state = '1'
				}

				if (!this.data.unitId && state == '0') {
					text = '请选择单元'
					state = '1'
				}

				if (!this.data.roomId && state == '0') {
					text = '请选择房屋'
					state = '1'
				}
				
				if (state == '1') {
					uni.showToast({
						title: text,
						icon: 'none',
						duration: 1500
					})
					return false
				}

				param = JSON.stringify(param)
				goToUrl(`/pages/home/roomInformation/roomInformation?param=${param}`)

			},

			/**
			 * 选择楼栋
			 */
			selectFloor() {
				uni.navigateTo({
					url: '../selectHome/selectFloors/selectFloors'
				})
			},
			/**
			 * 选择单元
			 */
			selectUnit() {
				if (!this.data.floorId) {
					uni.showToast({
						title: "请先选择楼栋",
						icon: 'none',
						duration: 1500
					})
					return
				}
				uni.navigateTo({
					url: `../selectHome/selectUnit/selectUnit?floorId=${this.data.floorId}`
				})
			},
			/**
			 * 选择房屋
			 */
			selectHouse() {
				if (!this.data.floorId) {
					uni.showToast({
						title: "请先选择楼栋",
						icon: 'none',
						duration: 1500
					})
					return
				}

				if (!this.data.unitId) {
					uni.showToast({
						title: "请先选择单元",
						icon: 'none',
						duration: 1500
					})
					return
				}
				uni.navigateTo({
					url: `../selectHome/selectHouse/selectHouse?floorId=${this.data.floorId}&unitId=${this.data.unitId}`
				})
			},
		}
	}
</script>

<style lang="scss">

</style>
